package com.zzty.training.controller;

import com.zzty.training.entity.User;
import com.zzty.training.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/main")
public class MainController {
    @Autowired
    UserService userService;
    @RequestMapping(value = "/getNameBySession",method = RequestMethod.POST)
    public String getNameBySession(HttpServletRequest request){
        HttpSession session = request.getSession();
        String name = String.valueOf(session.getAttribute("username"));
        return name;
    }
    @RequestMapping(value = "/getUserByName")
    public User getUserByName(User user){
        User user1=userService.getUserByName(user);
        return user1;
    }
}
